package com.alisiwei.core.base;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.alisiwei.util.UUIDUtlis;

@MappedSuperclass
public class BaseEntity {
	protected String id;
	protected Date create_date;
	protected String creater;
	protected Date update_date;
	protected String updater;
	
	/**
	 * 描述：新建对象初始：id,create_date,creater
	 * 作者：zhangkai
	 * @param entity
	 */
	public void init(BaseEntity entity,String user) {
		entity.setId(UUIDUtlis.getUUID());
		entity.setCreate_date(new Date());
		entity.setCreater(user);
	}
	
	/**
	 * 描述：修改对象记录修改时间：update_date,updater
	 * 作者：zhangkai
	 * @param entity
	 */
	public void change(BaseEntity entity,String user) {
		entity.setUpdate_date(new Date());
		entity.setUpdater(user);
	}
	
	@Id
	@Column(name = "ID", unique = true, nullable = false)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATE_DATE", length = 10)
	public Date getCreate_date() {
		return create_date;
	}
	public void setCreate_date(Date create_date) {
		this.create_date = create_date;
	}
	
	@Column(name = "CREATER", length = 255)
	public String getCreater() {
		return creater;
	}
	public void setCreater(String creater) {
		this.creater = creater;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "UPDATE_DATE", length = 10)
	public Date getUpdate_date() {
		return update_date;
	}
	public void setUpdate_date(Date update_date) {
		this.update_date = update_date;
	}
	
	@Column(name = "UPDATER", length = 255)
	public String getUpdater() {
		return updater;
	}
	public void setUpdater(String updater) {
		this.updater = updater;
	}
}
